package org.sqp.wechat.client;

import okhttp3.Cookie;
import okhttp3.CookieJar;
import okhttp3.HttpUrl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SimpleCookieJar implements CookieJar {
    Map<String, Cookie> cookies = new HashMap<String, Cookie>();

    public void saveFromResponse(HttpUrl httpUrl, List<Cookie> list) {
        for (Cookie cookie : list) {
            cookies.put(cookie.name(), cookie);
        }
    }

    public void add(Cookie cookie){
        cookies.put(cookie.name(),cookie);
    }

    public List<Cookie> loadForRequest(HttpUrl httpUrl) {
        return new ArrayList<Cookie>(cookies.values());
    }
}
